<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";
	
	date_default_timezone_set("PRC");
	
	if($_GET) {
		$class_id = $_GET["class_id"];
		$shop_id = $_GET["shop_id"];
		
		$sql = "SELECT shop.*, brand.name bname, class.name cname FROM shop LEFT JOIN brand ON (shop.brand_id = brand.id) LEFT JOIN class ON (brand.class_id = class.id) WHERE shop.id = $shop_id";
		
		$result = mysqli_query($conn, $sql);
		
		while($row = mysqli_fetch_array($result)) {
			$brand_id = $row["brand_id"];
			$cname = $row["cname"];
			$bname = $row["bname"];
			$name = $row["name"];
			$img = $row["img"];
			$pice = $row["pice"];
			$inventory = $row["inventory"];
		}
	}
?>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商城 - <?php echo $name; ?></title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="public/index.css"/>
	</head>

	<body>
		<div id="header">
			<div style="height: 40px;" class="container">
				<div class="header-left">
					<a href="index.php">商城</a>
				</div>
				<div class="header-right">
					<a href="registered.php">注册</a>
					<a href="login.php">登录</a>
					<a href="personal.php">个人中心</a>
					<a href="javascript:;">查看订单</a>
					<a href="cart/index.php">购物车</a>
				</div>
			</div>
		</div>
		<div id="main">
			<div class="container">
				<div class="shop">
					<div class="shop-title">
						<h4><span><a href="more.php?class_id=<?php echo $class_id; ?>"><?php echo $cname; ?></a> - <a href="brand.php?class_id=<?php echo $class_id; ?>&brand_id=<?php echo $brand_id; ?>"><?php echo $bname; ?></a> - </span><?php echo $name; ?></h4>
						<a href=""></a>
					</div>
					<div class="shop-img left"><img src='<?php echo $imgPath . $img; ?>'/></div>
					<div class="shop-details left">
						<h3><?php echo $name; ?></h3>
						<p>
							<span><?php echo $pice . "元"; ?></span>
							库存：<?php echo $inventory; ?>
						</p>
						<span style="text-align: right;display: block;">
							<a href="cart/car.php?shop_id=<?php echo $shop_id; ?>">+<img src="public/img/u=1631390123,844955119&fm=200&gp=0.jpg"/ title="加入购物车" width="50px" height="40px" ></a>
						</span>
						<div class="shop-comment">
							<h3>评论区</h3>
							<ul>
							<?php
								$sql = "SELECT comment.*, user.username FROM comment LEFT JOIN user ON (comment.user_id = user.id) WHERE comment.shop_id = $shop_id";
								
								$result = mysqli_query($conn, $sql);
								
								while($row = mysqli_fetch_array($result)) {
									echo "<li>
											<h6>" . $row["username"] . "</h6>
											<p>" . $row["content"] . "<span class='right'>" . date("Y-m-d H:i:s", $row["time"]) . "</span></p>
									</li>";
								}
								
								mysqli_close($conn);
							?>
							</ul>
						</div>
					</div>
				</div>
				
			</div>
		</div>
	</body>

</html>